package com.xyz.messagehelper.presenter

import com.xyz.messagehelper.contract.HomeContract
import com.xyz.messagehelper.utils.SharePreferenceUtils
import com.xyz.messagehelper.utils.Utils
import java.io.File
import kotlin.concurrent.thread

class HomePresenter(val homeView: HomeContract.View) : HomeContract.Presenter {

    override fun initPresenter() {

    }

    override fun onDestoryPresenter() {

    }


    override fun parseFileInfo(path: String) {
        SharePreferenceUtils.putString(Utils.context, "message_path", path)
        startParseFileInfo(path)
    }


    private fun startParseFileInfo(path: String) {
        thread {
            val file = File(path)
            var fileStrLine = ""
            var count = 0
            file.forEachLine {
                if (fileStrLine.isEmpty()) {
                    fileStrLine = it
                }
                count++;
            }
            runUiThread {
                homeView.shwowMessageTotalCount(count)
            }
        }
    }


}